import React from "react";
import BaseComponent from "../../redare/components/BaseComponent";
import Grid from "../../redare/components/grid/Grid";
import {Space} from "antd";
import ProjectPresenter from "../../.gen/presenter/ProjectPresenter";
import moment from "moment";
import {Link} from "react-router-dom";
import UserPresenter from "../../.gen/presenter/UserPresenter";
import {dateFormat} from "../utils/DateUtils";


export default class RUserSelectGrid extends BaseComponent {

    constructor(props) {
        super(props);
        this.presenter = new UserPresenter(this)
        this.selectData = []
    }

    componentDidMount() {
        this._findProjectPage()
    }

    //搜索
    _findProjectPage(searchParams, page) {
        if (this.grid) {
            this.grid.showLoadingIndicator()
        }
        this.searchParams = searchParams;
        if (!this.searchParams) {
            this.searchParams = {}
        }
        if (page) {
            this.curPage = page;
        }
        this.presenter.findUserPage(
            this.searchParams,
            {curPage: this.curPage, pageSize: this.pageSize},
            (result) => {
                let {data} = result;
                if (data && this.grid) {
                    let {result, curPage, pageSize, totalCount, totalPage} = data;
                    this.totalCount = totalCount;
                    this.totalPage = totalPage;
                    this.grid.setData(result, {curPage, pageSize, totalCount})
                }
            },
            () => {
                if (this.grid) {
                    this.grid.closeLoadingIndicator()
                }
            }
        )
    }

    onSelectChange = (selectedRowKeys, selectedRows) => {
        this.setState({selectedRowKeys});
        this.selectData = selectedRows;
    };

    _onSearch(values) {
        this._form.searchValues = values;
        this.grid._findProjectPage(values, 1);
    }

    //分页
    _changePage(curPage, pageSize) {
        this.curPage = curPage;
        this.pageSize = pageSize;
        this._findProjectPage(this.searchParams)
    }

    getSelectData() {
        return this.selectData;
    }

    render() {
        const {selectedRowKeys} = this.state;
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange,
        };
        return (
            <>
                {/*<ProjectSearchForm onSearchBtnClick={this._onSearch.bind(this)}/>*/}
                <Grid ref={(o) => {
                    this.grid = o
                }}
                      rowSelection={rowSelection}
                      border={false}
                      _initLoading={false}
                      scroll={{x: 'max-content'}}
                      bordered={false}
                      rowKey={(v) => v.id}
                      className={"margin-top24"}
                      _onPageChange={(page) => {
                          this._changePage(page.curPage, page.pageSize)
                      }}
                      columns={[
                          {
                              title: '账号',
                              dataIndex: 'account',
                              fixed: 'left',
                              width: 120,
                              _resizeable: true,
                              ellipsis: true,
                              _showTooltip: true,
                          },
                          {
                              title: '用户名',
                              dataIndex: 'name',
                              fixed: 'left',
                              width: 120,
                              _resizeable: true,
                              ellipsis: true,
                          },
                          {
                              title: '角色',
                              dataIndex: 'roleNames',
                              width: 150,
                              _resizeable: true,
                              ellipsis: true,
                              _showTooltip: true,
                          },
                          {
                              title: '状态',
                              align: 'center',
                              dataIndex: 'status',
                              width: 80,
                              render: (value, record, index) => {
                                  return value === 0 ? '正常' : '锁定';
                              }
                          },
                          {
                              title: '管理员',
                              align: 'center',
                              dataIndex: 'admin',
                              width: 80,
                              render: (value, record, index) => {
                                  return value ? '是' : '';
                              }
                          },
                          {
                              title: '手机号',
                              dataIndex: 'mobile',
                              width: 150,
                              _resizeable: true,
                              ellipsis: true,
                              _showTooltip: true,
                          },
                          {
                              title: '邮箱',
                              dataIndex: 'email',
                              width: 200,
                              _resizeable: true,
                              ellipsis: true,
                              _showTooltip: true,
                          }
                      ]}
                />
            </>

        )
    }

}





